﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyCongViec.Database;
using QuanLyCongViec.Common;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

namespace QuanLyCongViec.View
{
    public partial class FrmLoaiHopDong : Form
    {
        DataTable dtLoaiHD;
        dbLoaiHopDong db = new dbLoaiHopDong();
        private const string CAPTION_FORM = "Quản lý loại hợp đồng";
        private const string CAPTION_GROUP_HEADER = "Thông tin tìm kiếm";
        private const string CAPTION_GROUP_GRID = "Thông tin loại hợp đồng";
        private const string CAPTION_MALOAIHOPDONG = "Mã loại hợp đồng";
        private const string CAPTION_TENLOAIHOPDONG = "Tên loại hợp đồng";
        private const string CAPTION_THOIGIANNHAC = "Thời gian nhắc";


        private void InitControl()
        {
            lbMaLoaiHD.Text = CAPTION_MALOAIHOPDONG;
            btnSearch.Text = BtnControl.CAPTION_BTN_SEARCH;
            btnCreate.Text = BtnControl.CAPTION_BTN_CREATE;
            btnExit.Text = BtnControl.CAPTION_BTN_EXIT;
            gbHeader.Text = CAPTION_GROUP_HEADER;
            gbGrid.Text = CAPTION_GROUP_GRID;
            this.Text = CAPTION_FORM;
        }
        private void InitGrid()
        {
            MaLoaiHopDong.Caption = CAPTION_MALOAIHOPDONG;
            TenLoaiHopDong.Caption = CAPTION_TENLOAIHOPDONG;
            ThoiGianNhac.Caption = CAPTION_THOIGIANNHAC;

            MaLoaiHopDong.FieldName = TblLoaiHopDong.MaLoaiHD;
            TenLoaiHopDong.FieldName = TblLoaiHopDong.TenLoaiHD;
            ThoiGianNhac.FieldName = TblLoaiHopDong.ThoiGianNhac;
            LoaiHopDongID.FieldName = TblLoaiHopDong.LoaiHopDongID;
            dtLoaiHD = db.LoaiHopDongGet("", "");
            gridLoaiHD.DataSource = dtLoaiHD;
            gviewLoaiHD.OptionsBehavior.Editable = false;
        }
        private void Search()
        {
            dtLoaiHD = db.LoaiHopDongGet("", txtMaLoaiHD.Text);
            gridLoaiHD.DataSource = dtLoaiHD;
        }
        public FrmLoaiHopDong()
        {
            InitializeComponent();
        }

        private void FrmLoaiHopDong_Load(object sender, EventArgs e)
        {
            InitControl();
            InitGrid();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            Search();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            FrmLoaiHopDongCreate frm = new FrmLoaiHopDongCreate();
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
        }

        private void gviewLoaiHD_DoubleClick(object sender, EventArgs e)
        {
            FrmLoaiHopDongModify frm = new FrmLoaiHopDongModify();
            MouseEventArgs me = e as MouseEventArgs;
            MouseButtons btn = me.Button;
            int x = me.X;
            int y = me.Y;
            GridHitInfo hit = gviewLoaiHD.CalcHitInfo(x, y);
            if (hit.InRowCell)
            {
                DataRow dr = gviewLoaiHD.GetDataRow(gviewLoaiHD.FocusedRowHandle);
                frm.LoaiHopDongID = dr[TblLoaiHopDong.LoaiHopDongID].ToString();
                frm.StartPosition = FormStartPosition.CenterScreen;
                frm.ShowDialog();
            }
        }
    }
}
